
const path = require('path')
const glob = require('glob')
const START_PATH = './src/entries'
const entriesPath = path.resolve(__dirname, START_PATH)

exports.pages = function() {
    const obj = {}
    const histroyReWrite = []
    console.log(entriesPath + '/**/*.html')
    glob.sync(entriesPath + '/**/*.html').forEach((filePath) => {
        console.log(filePath)
        const dirPath = filePath.substring(0, filePath.lastIndexOf('/'))
        const dirName = dirPath.substring(dirPath.lastIndexOf('/')+1)
        obj[dirName] = {
            entry: filePath.substring(0, filePath.lastIndexOf('.html')) + '_main.js',
            template: filePath,
            chunks: ["chunk-vendors", "chunk-common", dirName]
        }
        histroyReWrite.push({
            from: new RegExp(`${dirName}.*`),
            to: `/${dirName}.html`
        })
    })
    console.log(histroyReWrite)
    histroyReWrite.push({
        from: /.*/,
        to: histroyReWrite[0].to
    })
    console.log(histroyReWrite)
    return {pages: obj, histroyReWrite: histroyReWrite}
}